import moment from 'moment/moment';

const tableOption = {
  border: true,
  addBtn: false,
  viewBtn: false,
  editBtn: false,
  delBtn: false,
  index: true,
  menu: false,
  columnBtn: false,
  refreshBtn: false,
  indexLabel: '序号',
  column: [
    {
      label: '日期',
      prop: 'statisticsTime'
    },
    {
      label: '车间名称',
      prop: 'workshopName'
    },
    {
      label: '检验数量',
      prop: 'inspectionQuantity'
    },
    {
      label: '全检不良总数',
      prop: 'inspectionNgQuantity',
      span: 7
    },
    {
      label: '全检不良率（PPM）',
      prop: 'inspectionNgRate'
    },
    {
      label: '目标值',
      prop: 'workshopPpmTargetValue'
    },
    {
      label: '是否达标',
      prop: 'complianceFlag'
    }
  ]
};

const option = {
  menuPosition: 'right',
  submitBtn: false,
  emptyBtn: false,
  column: [
    {
      label: '统计维度',
      prop: 'statisticsTimeDimension',
      type: 'radio',
      button: true,
      span: 4,
      value: 'DAY',
      dicData: [
        {
          label: '日',
          value: 'DAY'
        },
        {
          label: '月',
          value: 'MONTH'
        }
      ],
      control: (val, form) => {
        if (val === 'DAY') {
          return {
            examineDate: {
              display: true
            },
            month: {
              display: false
            }
          };
        } else {
          return {
            examineDate: {
              display: false
            },
            month: {
              display: true
            }
          };
        }
      }
    },
    {
      label: '时间范围',
      span: 6,
      prop: 'examineDate',
      type: 'daterange',
      format: 'yyyy-MM-dd',
      valueFormat: 'yyyy-MM-dd',
      startPlaceholder: '开始日期',
      endPlaceholder: '结束日期',
      // pickerOptions: {
      //   disabledDate(time) {
      //     return time.getTime() > Date.now() || moment(time).format('yyyy-MM-DD') === moment(new Date()).format('yyyy-MM-DD');
      //   }
      // },
      rules: [
        {
          required: true,
          message: '请选择时间范围',
          trigger: 'blur'
        },
        {
          trigger: 'change',
          validator: (rule, value, callback) => {
            const endTime = value[1];
            const startTime = value[0];
            if (moment(endTime).diff(moment(startTime), 'day') > 59) {
              callback(new Error('查询时间最多选择60天'));
            }
            callback();
          }
        }
      ]
    },
    {
      label: '时间范围',
      span: 6,
      prop: 'month',
      type: 'monthrange',
      format: 'yyyy-MM',
      startPlaceholder: '开始月份',
      endPlaceholder: '结束月份',
      valueFormat: 'yyyy-MM-dd',
      rules: [
        {
          required: true,
          message: '请选择时间范围',
          trigger: 'blur'
        }
      ]
    },
    {
      label: '车间名称',
      prop: 'workshopName',
      span: 6
      // rules: [
      //   {
      //     required: true,
      //     message: '请输入车间名称',
      //     trigger: 'blur'
      //   }
      // ]
    },
    {
      label: '',
      prop: 'btn',
      span: 6,
      formslot: true
    }
  ]
};

export { tableOption, option };
